package edu.hgnc.selfBDRPP;

import edu.hgnc.beans.Student;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.*;

public class CustomBeanDefinitionRegisterPostProcessor implements BeanDefinitionRegistryPostProcessor {
	/**
	 * Modify the application context's internal bean factory after its standard
	 * initialization.
	 * */
	@Override
	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
		System.out.println("CustomBeanDefinitionRegisterPostProcessor----执行了postProcessBeanFactory方法");
	}

	/**
	 * Modify the application context's internal bean definition registry after its
	 * standard initialization.
	 */
	@Override
	public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
		System.out.println("CustomBeanDefinitionRegisterPostProcessor----执行了postProcessBeanDefinitionRegistry方法");
		// 两种方法注入bean定义信息
		// 方式1，直接new 一个BeanDefinition接口的实现类，传入要描述bean的类字节码
		// BeanDefinition beanDefinition = new RootBeanDefinition(Student.class);
		// 方式2，用BeanDefinitionBuilder工具类
		// BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(Student.class);
		// builder.addPropertyValue("name","张三");
		// builder.addPropertyValue("no","001");
		// builder.addPropertyValue("classId","3");
		// builder.addPropertyValue("gender","男");

		// 用BeanDefinition把BeanDefinitionRegisterPostProcessor2实现排序的添加进来
		BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(CustomBeanDefinitionRegisterPostProcessor2.class);
		BeanDefinition beanDefinition = builder.getBeanDefinition();



		registry.registerBeanDefinition("student",beanDefinition);
	}
}
